public class Ave {
    public static double ave(int []arr)
    {
        int sum=0;
        for(int x:arr)//foreach语句遍历数组
        {
            sum+=x;
        }
        return sum*1.0/arr.length;//自动类型转换int变double
    }
    public static void main(String[] args) {
        int []arr={1,5,8,8,9,7};
        double average=ave(arr);
        System.out.println("平均数："+average);
    }
}
